<script>
	import { mapState, mapMutations } from 'vuex';
	import Base64 from "base-64";
	import {getOpenIdByCode, generalQueryByTableName,generalQueryBySQLSerialNumber,generalWeChatOpenID} from '@/api/generalBusiness.js';
	export default {
		data() {
			return {
			
			}
		},
		onLaunch: function() {
			console.log('初始化..')
			uni.login({
				provider: "weixin",
				success: (loginRes) => {
					this.getOpenID(loginRes.code, this.App_ID , (res)=>{
						if(res.Status=='success'){
							this.setOpenID(res.Data.Open_ID);
							this.setMember(res.Data);
							
							this.getData(res.Data.Open_ID);
							if(res.NewMember == '1'){
								uni.showModal({
									title: "提示",
									content: "未绑定用户身份是否前往绑定",
									success: function(res) {
										if (res.confirm) {
											uni.navigateTo({url: "/pages/index/login"});
										}
									},
								});
							}
							
						}
					})
				},
			})
			
		},
		computed:{
			...mapState(['Open_ID','App_ID','Member','WS_URL','BASE_IMG','Enterprise_Info_SerialNumber']),
		},
		methods:{
			...mapMutations(['setBASEPath','setHOMEPage','setOpenID','setPointConfig','setMember','setBASEQuery','modifyShopNum']),
			async getData(Open_ID){//页面
				const res1 = await generalQueryBySQLSerialNumber({
					SQLSerialNumber:'C_business_points_config',
					Condition:'',
					ExtensionCondition:''
				}) 
				if(res1.length==1){
					this.setPointConfig(res1[0]);
				}
				const res2 = await generalQueryByTableName({
					TableName:'base_page_info',
					Condition: "Row_Status <> '1' and App_ID='1'"
				})
				if(res2.length == 1){
					this.setBASEQuery({});//传参
					this.setHOMEPage(`/${res2[0].Page_SerialNumber}.html`)//首页
					this.setBASEPath(`/${res2[0].Page_SerialNumber}.html`);//跳转路径
				}
				const res3 = await generalQueryBySQLSerialNumber({
					SQLSerialNumber:'M_business_shopping_trolley_Quantity',
					Condition:Base64.encode(Open_ID),
					ExtensionCondition:''
				})
				if(res3.length == 1){
					this.modifyShopNum(res3[0].Quantity)
				}
			},
			async getOpenID(Code,App_ID,callback){
				callback(await generalWeChatOpenID({Code,App_ID}));
			},
			async getOpenIdByCode(Code,callback){
				callback(await getOpenIdByCode({Code}));
			}
		}
	}
</script>

<style>
	/*每个页面公共css */
	@import "static/css/free.css";
</style>
